package view;


import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class DragView extends android.support.v7.widget.AppCompatImageView {
    float moveX;
    float moveY;

    public DragView(Context context) {
        super(context);
    }

    public DragView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setTranslationX(860);
        setTranslationY(410);

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                moveX = event.getX();
                moveY = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                float rawX = event.getRawX();
                float rawY = event.getRawY();

//              <34 > 997
                if (rawX >= 40 && rawX <= 990 ) {
                    setTranslationX(getX() + (event.getX() - moveX));
                }
                // >278  <740
                if (rawY >= 278 && rawY <= 730) {
                    setTranslationY(getY() + (event.getY() - moveY));
                }
                break;
            case MotionEvent.ACTION_UP:
                break;
            case MotionEvent.ACTION_CANCEL:
                break;
        }

        return true;
    }

}
